package kin.converter;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;

import kin.context.system.RequestContext;

public class ParamUtil {
public static Object setParam(Class cls){
	HttpServletRequest req=RequestContext.getRequest();
	Map<String,String[]> par=req.getParameterMap();
	Set<String> keys=par.keySet();
	Object obj=null;
	try {
		obj=cls.newInstance();
		for(String key:keys){
			
				String[] val=par.get(key);
				if(val.length>1){
					ARPBeanUtils.copyProperty(obj, key, par.get(key));
				}else{
					ARPBeanUtils.copyProperty(obj, key, par.get(key)[0]);
				}
		
		}
	} catch (InstantiationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IllegalAccessException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (SecurityException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
	return obj;
	
}
}
